layui.define(['http'], function (exports) {

	function BaseServices(apiModule) {
		this.service = layui.http.service;
		this.apiModule = apiModule;
	}

	BaseServices.prototype = {
		constructor: BaseServices,
		/**
		 * @author: ares
		 * @date: 2021/4/24 11:29
		 * @description:  创建
		 * @param {object}data
		 * @returns {Promise.<TResult>}
		 */
		create: function (data) {
			return this.service(this.apiModule.api.create, {method: 'post', data: data});
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:31
		 * @description: 删除
		 * @param {string}id
		 * @returns {Promise.<TResult>}
		 */
		remove: function (id) {
			return this.service(this.apiModule.api.remove + `/${id}`);
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:32
		 * @description: 更新
		 * @param {object}data
		 * @returns {Promise.<TResult>}
		 */
		update: function (data) {
			return this.service(this.apiModule.api.update, {method: 'update', data: data});
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:33
		 * @description: 获取列表
		 * @returns {Promise.<TResult>}
		 */
		getList: function () {
			return this.service(this.apiModule.api.list);
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:34
		 * @description: 基本分页查询
		 * @param {number}pageNum  当前页
		 * @param {number}pageSize 分页限制
		 * @param {object}params   其它参数
		 * @returns {Promise.<TResult>}
		 */
		getPageList: function (pageNum = 1, pageSize = 10, params = {}) {
			let _params = {
				pageNum,
				pageSize,
			};
			Object.assign(_params, params);
			return this.service(this.apiModule.api.getPageList, {params: _params});
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:35
		 * @description: 增强型分页查询
		 * @param {number}pageIndex  当前页
		 * @param {number}pageSize 分页限制
		 * @param {object}params   其它参数
		 * @returns {Promise.<TResult>}
		 */
		postPageList: function (pageNum = 1, pageSize = 10, params) {
			let data = {
				pageNum,
				pageSize,
				...params
			};
			return this.service(this.apiModule.api.postPageList, {method: 'post', data: data});
		},

		/**
		 * @author: ares
		 * @date: 2021/4/24 11:36
		 * @description: 查询详情
		 * @param {string}id
		 * @returns {Promise.<TResult>}
		 */
		getDetail: function (id) {
			return this.service(this.apiModule.api.detail + `/${id}`);
		},
	}
	exports('BaseServices', BaseServices);
})